﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using kripto2._1.operation;

namespace kripto2._1.algorithm
{
    class ECB
    {
        //Pada mode ECB, blok plainteks yang sama selalu dienkripsi menjadi blok cipherteks yang sama. 
        static int jumlahblock;
        static int blocksize;

        public static byte[] encrypt(byte[] message, byte[] key)
        {
            blocksize = key.Length;
            jumlahblock = message.Length / blocksize;

            byte[] hasil = new byte[message.Length];
            for (int i = 0; i < jumlahblock; i++)
            {
                byte[] currentblock = generateTrueKey.getNbyteKey(message, i * blocksize, blocksize);
                byte[] currentcipher = feistel.feistelencrypt(currentblock, key);
                currentcipher.CopyTo(hasil, i * blocksize);
            }

            return hasil;
        }

        public static byte[] decrypt(byte[] message, byte[] key)
        {
            blocksize = key.Length;
            jumlahblock = message.Length / blocksize;

            byte[] hasil = new byte[message.Length];
            for (int i = 0; i < jumlahblock; i++)
            {
                byte[] currentblock = generateTrueKey.getNbyteKey(message, i * blocksize, blocksize);
                byte[] currentplain = feistel.feisteldecrypt(currentblock, key);
                currentplain.CopyTo(hasil, i * blocksize);
            }

            return hasil;
        }
    }
}
